package cn.edu.scut.hsrc.bean;

import cn.edu.scut.hsrc.bean.WordType.Type;

/**
 * 定义一个词
 * @file Word.java
 * @author feiyu
 *
 */

public class Word{
	
	public enum RelationToQuery{
		NOTHING,	//没关系
		EQUAL,		//相等
		RINCLUDE,	//查询词包含该词
		INCLUDE		//该词包含查询词
	};
	
	private final String text;		//词
	private final Type type;		//词性
	private final RelationToQuery relationToQuery;//和查询词关系
	
	/**
	 * 
	 * 构造函数
	 * @param text	词
	 * @param type	词性
	 * @param relationToQuery	和查询词关系得分
	 */
	public Word(String text,Type type,RelationToQuery relationToQuery) {
		// TODO Auto-generated constructor stub
		this.text = text;
		this.type = type;
		this.relationToQuery = relationToQuery;
	}
	
	/**
	 * 赋值构造函数
	 * 构造函数
	 * @param word
	 */
	public Word(Word word)
	{
		this.text = word.text;
		this.type = word.type;
		this.relationToQuery = word.relationToQuery;
	}
	
	/**
	 * 
	 * @return 返回词字符串
	 */
	public String getText() {
		return this.text;
	}
	
	/**
	 * 返回该词和查询词之间的关系
	 * @return
	 */
	public RelationToQuery getRelationToQuery() {
		return this.relationToQuery;
	}
	
	/**
	 * 返回词的长度
	 * @return
	 */
	public int length() {
		return this.text.length();
	}

	/**
	 * 
	 * @return 返回词的词性
	 */
	public Type getType() {
		return this.type;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return this.text;
	}

	/**
	 * 判断两个词是否相等，这里只是比对他们本身包含的字符串是否相等，如果相等返回true，否则返回false
	 */
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if(obj instanceof Word)
			return this.text.equals(((Word)obj).text);
		return false;
	}
}

